#!/usr/bin/env bash
# 清除之前运行数据
# docker ps -a  |awk '{print $1}'|xargs docker rm
# docker images |grep "<none>"  |awk '{print $3}'|xargs docker rmi

docker ps -a|grep Exited |awk '{print $1}'|xargs docker rm >/dev/null 2>&1
hn=`cat /etc/hostname`
echo $hn
if [ "$hn" = "wolferhua-dell" ]; then
    ip=`ifconfig wlp2s0|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
elif [ "$hn" = "wolferhua-PC" ]; then
    ip=`ifconfig wlp3s0|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
else
    ip=`ifconfig enp2s0|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"`
fi
echo $ip


docker ps -a|grep php56 |awk '{print $1}'|xargs -t docker stop >/dev/null 2>&1
docker ps -a|grep php56 |awk '{print $1}'|xargs -t docker rm >/dev/null 2>&1

# php 5.6
echo step1 5.6
docker run -d \
--privileged=true \
--name php56 \
-d \
-v /home/duyu/workspace/dockers/duyu/php56/etc:/usr/local/etc \
-v /home/duyu/workspace/php:/www \
--add-host=admin.renren.com:$ip \
--add-host=dev.renren.com:$ip \
--restart=always \
 wolferhua/php:5.6-fpm

docker ps -a|grep php72 |awk '{print $1}'|xargs docker kill >/dev/null 2>&1
docker ps -a|grep php72 |awk '{print $1}'|xargs docker rm >/dev/null 2>&1

# php 7
echo step2 7.2
docker run -d --name php72 \
-d \
-v /home/duyu/workspace/php:/www \
-v /home/duyu/workspace/dockers/duyu/php72/etc:/usr/local/etc \
--add-host=admin.renren.com:$ip \
--add-host=dev.renren.com:$ip \
--add-host=seller.renren.com:$ip \
--add-host=iapp.renren.com:$ip \
--add-host=app.renren.com:$ip \
--add-host=api.renren.com:$ip \
--add-host=localhost:$ip \
--restart=always \
 wolferhua/php:7.2-fpm

docker ps -a|grep memcached |awk '{print $1}'|xargs docker kill >/dev/null 2>&1
docker ps -a|grep memcached |awk '{print $1}'|xargs docker rm >/dev/null 2>&1

#启动memcahced
echo step3 memcached

docker run --name memcached \
-d \
-p 11211:11211 \
--restart=always \
dyucloud/memcached

docker ps -a|grep nginx80 |awk '{print $1}'|xargs docker kill >/dev/null 2>&1
docker ps -a|grep nginx80 |awk '{print $1}'|xargs docker rm >/dev/null 2>&1

# 启动nginx
echo step4 nginx
docker run --name nginx80 \
--link php56:php56 \
--link php72:php72 \
--link memcached:memcached \
-d \
-v /home/duyu/workspace/dockers/duyu/nginx/conf:/etc/nginx \
-v /home/duyu/workspace/php:/www \
-p 80:80 \
--restart=always \
wolferhua/nginx:1.13.6